<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Class List extends Modules_Controller 
 * @author era
 * 清单
 */
class Lists extends Modules_Controller
{
   	protected $rules = array(
		"create" => array(
			array(
				"field" => "title",
				"label" => "标题",
				"rules" => "trim|required"
			),
		)
		,"edit" => array(
			array(
				"field" => "id",
				"label" => "标识",
				"rules" => "trim|required|numeric"
			),
			array(
				"field" => "title",
				"label" => "标题",
				"rules" => "trim|required"
			),
		)	
	); 

	protected function _create_data(){
		$form=$this->input->post();
		$form['timeline'] = time();
		$form['ccid'] = $this->ccid;
		if ($this->cid == 34) {
			
			$form['content'] = $this->getCode();
		}
		
		return $form;
	}

	// 生成激活码
    protected function getCode() {
        $code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';    
        $rand = $code[rand(0,25)]    
            .strtoupper(dechex(date('m')))    
            .date('d').substr(time(),-5)    
            .substr(microtime(),2,5)
            .sprintf('%02d',rand(0,99));    
        for(    
            $a = md5( $rand, true ),    
            $s = '0123456789ABCDEFGHIJKLMNOPQRSTUV',    
            $d = '',    
            $f = 0;    
            $f < 8;    
            $g = ord( $a[ $f ] ),    
            $d .= $s[ ( $g ^ ord( $a[ $f + 8 ] ) ) - $g & 0x1F ],    
            $f++    
        );    
        return $d;    
    }


	public function _edit_data()
	{
		$form=$this->input->post();
		$form['timeline'] = time();
		$form['ccid'] = $this->ccid;
		return $form;
	}

	protected function _search_where(){
		return false;
	}
}
